package coop.bancocredicoop.proyectos.gd.alfresco;

import coop.bancocredicoop.proyectos.gd.alfresco.AlfrescoHttpClient;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpRequest;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;

class AlfrescoHttpClientWithExplorer extends AlfrescoHttpClient {
    
	private static final Log log = LogFactory.getLog(AlfrescoHttpClient.class);
    private String username;

    AlfrescoHttpClientWithExplorer(AlfrescoConfig alfrescoConfig, String username) {
        super(alfrescoConfig);
        this.username = username;
    }

    @Override
    public void beforeGet(HttpClient httpClient, HttpGet httpGet) {
        setUserInHeader(httpGet);
    }

	@Override
	public void beforePost(HttpClient client, HttpPost post) {
		setUserInHeader(post);
	}
    
    private void setUserInHeader(HttpRequest request) {
    	log.debug(String.format("Acting as user: %s", username));
        request.setHeader("X-Alfresco-Remote-User", username);
    }



}